<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Indexer &mdash; SIMULATeQCD 0.7 documentation</title>
      <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
      <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
      <link rel="stylesheet" href="../_static/togglebutton.css" type="text/css" />
      <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  <!--[if lt IE 9]>
    <script src="../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="../_static/togglebutton.js"></script>
        <script>var togglebuttonSelector = '.toggle, .admonition.dropdown';</script>
        <script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
        <script>window.MathJax = {"options": {"processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>
    <script src="../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="File Writer" href="fileWriter.html" />
    <link rel="prev" title="Code base" href="codeBase.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #343131" >
            <a href="../index.html" class="icon icon-home"> SIMULATeQCD
          </a>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../01_gettingStarted/gettingStarted.html">Getting started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../02_contributions/contributions.html">Contributions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../03_applications/applications.html">Applications</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="codeBase.html">Code base</a><ul class="current">
<li class="toctree-l2 current"><a class="current reference internal" href="#">Indexer</a></li>
<li class="toctree-l2"><a class="reference internal" href="fileWriter.html">File Writer</a></li>
<li class="toctree-l2"><a class="reference internal" href="latticeContainer.html">Lattice Container</a></li>
<li class="toctree-l2"><a class="reference internal" href="communicationBase.html">Communication</a></li>
<li class="toctree-l2"><a class="reference internal" href="functorSyntax.html">Functor syntax</a></li>
<li class="toctree-l2"><a class="reference internal" href="gaugefield.html">Gaugefield</a></li>
<li class="toctree-l2"><a class="reference internal" href="topology.html">Topology</a></li>
<li class="toctree-l2"><a class="reference internal" href="configurationIO.html">Input and output formats for gauge configurations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../05_modules/modules.html">Modules</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu"  style="background: #343131" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">SIMULATeQCD</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../index.html" class="icon icon-home"></a> &raquo;</li>
          <li><a href="codeBase.html">Code base</a> &raquo;</li>
      <li>Indexer</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../_sources/04_codeBase/indexer.md.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section class="tex2jax_ignore mathjax_ignore" id="indexer">
<h1>Indexer<a class="headerlink" href="#indexer" title="Permalink to this headline"></a></h1>
<p>When working with 4-<span class="math notranslate nohighlight">\(d\)</span> lattices, we need a way to map the lattices sites (given by spacetime coordinates <span class="math notranslate nohighlight">\((x,y,z,t)\)</span> to the computer memory,
which is 1-dimensional. This gets more complicated when using multi-GPU, since we have to care about sub-lattices and halos.
For many algorithms it is convenient to characterize sites as even or odd. A site is even (odd) if <span class="math notranslate nohighlight">\(x+y+z+t\)</span> is even (odd).</p>
<section id="terminology">
<h2>Terminology<a class="headerlink" href="#terminology" title="Permalink to this headline"></a></h2>
<p>The 1-<span class="math notranslate nohighlight">\(d\)</span> memory index (which is just an integer) is often called <code class="docutils literal notranslate"><span class="pre">isite</span></code> throughout the code.
The four spacetime coordinates of a lattice site are stored in a <code class="docutils literal notranslate"><span class="pre">struct</span></code> named <code class="docutils literal notranslate"><span class="pre">sitexyzt</span></code>.
When using multi-GPU we use the following terminology:</p>
<ul class="simple">
<li><p>original lattice (without any splitting or halos): <strong>global</strong> lattice</p></li>
<li><p>sub-lattice with halos: <strong>full</strong> sub-lattice</p></li>
<li><p>sub-lattice without halos: <strong>bulk</strong> sub-lattice</p></li>
</ul>
</section>
<section id="memory-layout-and-basic-indexing">
<h2>Memory layout and basic indexing<a class="headerlink" href="#memory-layout-and-basic-indexing" title="Permalink to this headline"></a></h2>
<p>In SIMULATeQCD we sometimes want to exploit symmetries of the Dirac matrix, which requires an even-odd memory layout. We first store the data for all
of the even sites and then for all of the odd sites, contiguously. This is how it is done for all of the base classes like
<code class="docutils literal notranslate"><span class="pre">Gaugefield</span></code>, <code class="docutils literal notranslate"><span class="pre">Spinorfield</span></code>, <code class="docutils literal notranslate"><span class="pre">LatticeContainer</span></code>, etc.
The conversion looks like this:</p>
<div class="highlight-C++ notranslate"><div class="highlight"><pre><span></span><span class="kt">size_t</span><span class="w"> </span><span class="nf">siteLocal</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">sitexyzt</span><span class="w"> </span><span class="n">coord</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="p">(((</span><span class="n">coord</span><span class="p">.</span><span class="n">x</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">coord</span><span class="p">.</span><span class="n">y</span><span class="o">*</span><span class="n">getLatData</span><span class="p">().</span><span class="n">vol1</span><span class="w"></span>
<span class="w">                      </span><span class="o">+</span><span class="w"> </span><span class="n">coord</span><span class="p">.</span><span class="n">z</span><span class="o">*</span><span class="n">getLatData</span><span class="p">().</span><span class="n">vol2</span><span class="w"></span>
<span class="w">                      </span><span class="o">+</span><span class="w"> </span><span class="n">coord</span><span class="p">.</span><span class="n">t</span><span class="o">*</span><span class="n">getLatData</span><span class="p">().</span><span class="n">vol3</span><span class="p">)</span><span class="w"> </span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="mh">0x1</span><span class="p">)</span><span class="w"> </span><span class="c1">// integer division by 2</span>
<span class="w">    </span><span class="o">+</span><span class="n">getLatData</span><span class="p">().</span><span class="n">sizeh</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="p">((</span><span class="n">coord</span><span class="p">.</span><span class="n">x</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">coord</span><span class="p">.</span><span class="n">y</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">coord</span><span class="p">.</span><span class="n">z</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">coord</span><span class="p">.</span><span class="n">t</span><span class="p">)</span><span class="w"> </span><span class="o">&amp;</span><span class="w"> </span><span class="mh">0x1</span><span class="p">));</span><span class="w"> </span><span class="c1">// 0 if x+y+z+t is even, 1 if odd</span>
<span class="p">}</span><span class="w"></span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">sizeh</span></code> here is the number of of lattice sites divided by 2. (We use bit shifts to divide to improve performance.)
For objects that don’t store data on all lattice points, but only the odd part, one needs a mapping like this:</p>
<div class="highlight-C++ notranslate"><div class="highlight"><pre><span></span><span class="kt">size_t</span><span class="w"> </span><span class="nf">siteLocal_eo</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">sitexyzt</span><span class="w"> </span><span class="n">coord</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="p">((</span><span class="n">coord</span><span class="p">.</span><span class="n">x</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">coord</span><span class="p">.</span><span class="n">y</span><span class="o">*</span><span class="n">getLatData</span><span class="p">().</span><span class="n">vol1</span><span class="w"></span>
<span class="w">                     </span><span class="o">+</span><span class="w"> </span><span class="n">coord</span><span class="p">.</span><span class="n">z</span><span class="o">*</span><span class="n">getLatData</span><span class="p">().</span><span class="n">vol2</span><span class="w"></span>
<span class="w">                     </span><span class="o">+</span><span class="w"> </span><span class="n">coord</span><span class="p">.</span><span class="n">t</span><span class="o">*</span><span class="n">getLatData</span><span class="p">().</span><span class="n">vol3</span><span class="p">)</span><span class="w"> </span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="mh">0x1</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>
</div>
<p>This can of course also be used for objects that only store the even part, as adjacent odd and even sites are mapped to same index.
Sometimes one wants to obtain the coordinates from the corresponding 1-<span class="math notranslate nohighlight">\(d\)</span> memory index, i.e one wants to deindex.
That can be done like this:</p>
<div class="highlight-C++ notranslate"><div class="highlight"><pre><span></span><span class="n">sitexyzt</span><span class="w"> </span><span class="nf">de_site</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">site</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kt">int</span><span class="w"> </span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">,</span><span class="w"> </span><span class="n">z</span><span class="p">,</span><span class="w"> </span><span class="n">t</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kt">int</span><span class="w"> </span><span class="n">par</span><span class="p">,</span><span class="w"> </span><span class="n">normInd</span><span class="p">,</span><span class="w"> </span><span class="n">tmp</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="c1">//! figure out the parity:</span>
<span class="w">    </span><span class="n">divmod</span><span class="p">(</span><span class="n">site</span><span class="p">,</span><span class="w"> </span><span class="n">getLatData</span><span class="p">().</span><span class="n">sizeh</span><span class="p">,</span><span class="w"> </span><span class="n">par</span><span class="p">,</span><span class="w"> </span><span class="n">normInd</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="c1">//! par now contains site/sizeh (integer division), so it should be 0 (even) or 1 (odd).</span>
<span class="w">    </span><span class="c1">//! normInd contains the remainder. Adjacent odd and even sites will have the same remainder.</span>

<span class="w">    </span><span class="c1">//! Now think of an interlaced list of all even and all odd sites, such that the entries alternate</span>
<span class="w">    </span><span class="c1">//! between even and odd sites. Since adjacent sites have the same remainder, the remainder functions as</span>
<span class="w">    </span><span class="c1">//! the index of the *pairs* of adjacent sites. The next step is now to double this remainder so that</span>
<span class="w">    </span><span class="c1">//! we can work with it as an index for the single sites and not the pairs.</span>
<span class="w">    </span><span class="n">normInd</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">normInd</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="mh">0x1</span><span class="p">;</span><span class="w"> </span><span class="c1">//! multiply remainder by two</span>

<span class="w">    </span><span class="c1">//! Now get the slower running coordinates y,z,t:</span>
<span class="w">    </span><span class="c1">//! To get these, we simply integer-divide the index by the product of all faster running lattice extents,</span>
<span class="w">    </span><span class="c1">//! and then use the remainder as the index for the next-faster coordinate and so on.</span>
<span class="w">    </span><span class="n">divmod</span><span class="p">(</span><span class="n">normInd</span><span class="p">,</span><span class="w"> </span><span class="n">getLatData</span><span class="p">().</span><span class="n">vol3</span><span class="p">,</span><span class="w"> </span><span class="n">t</span><span class="p">,</span><span class="w"> </span><span class="n">tmp</span><span class="p">);</span><span class="w"> </span><span class="c1">//! t now contains normInd/vol3, tmp the remainder</span>
<span class="w">    </span><span class="n">divmod</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span><span class="w">     </span><span class="n">getLatData</span><span class="p">().</span><span class="n">vol2</span><span class="p">,</span><span class="w"> </span><span class="n">z</span><span class="p">,</span><span class="w"> </span><span class="n">tmp</span><span class="p">);</span><span class="w"> </span><span class="c1">//! z now contains tmp/vol2, tmp the remainder</span>
<span class="w">    </span><span class="n">divmod</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span><span class="w">     </span><span class="n">getLatData</span><span class="p">().</span><span class="n">vol1</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">,</span><span class="w"> </span><span class="n">x</span><span class="p">);</span><span class="w">   </span><span class="c1">//! x now contains tmp/vol1, x the remainder</span>

<span class="w">    </span><span class="c1">//! One problem remains: since we doubled the remainder and since the lattice extents have to be even,</span>
<span class="w">    </span><span class="c1">//! x is now also always even, which is of course not correct. We may need to correct it to be odd, depending</span>
<span class="w">    </span><span class="c1">//! on the supposed parity we found in the beginning, and depending on whether y+z+t is even or odd:</span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="o">!</span><span class="n">isOdd</span><span class="p">(</span><span class="n">x</span><span class="p">)){</span><span class="w"></span>
<span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="w">   </span><span class="p">(</span><span class="w"> </span><span class="n">par</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="o">!</span><span class="n">isOdd</span><span class="p">(</span><span class="n">y</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">t</span><span class="p">))</span><span class="w">       </span><span class="c1">//! odd parity but y+z+t is even, so x should be odd</span>
<span class="w">               </span><span class="n">or</span><span class="w"> </span><span class="p">(</span><span class="o">!</span><span class="n">par</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w">  </span><span class="n">isOdd</span><span class="p">(</span><span class="n">y</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">t</span><span class="p">)))</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">//! even parity but y+z+t is  odd, so x should be odd</span>
<span class="w">            </span><span class="o">++</span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="c1">//! Note that we always stay inside of a pair of adjacent sites when incrementing x here.</span>

<span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="n">sitexyzt</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">,</span><span class="w"> </span><span class="n">z</span><span class="p">,</span><span class="w"> </span><span class="n">t</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>
</div>
<p>Obtaining only either even or odd sites from the 1-<span class="math notranslate nohighlight">\(d\)</span> memory index
is done in a very similar way, except we dictate the parity:</p>
<div class="highlight-C++ notranslate"><div class="highlight"><pre><span></span><span class="n">sitexyzt</span><span class="w"> </span><span class="nf">de_site_eo</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">site</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">par</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kt">int</span><span class="w"> </span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">,</span><span class="w"> </span><span class="n">z</span><span class="p">,</span><span class="w"> </span><span class="n">t</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kt">int</span><span class="w"> </span><span class="n">tmp</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kt">size_t</span><span class="w"> </span><span class="n">sited</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">site</span><span class="o">&lt;&lt;</span><span class="mh">0x1</span><span class="p">;</span><span class="w"> </span><span class="c1">// multiply by two</span>

<span class="w">    </span><span class="n">divmod</span><span class="p">(</span><span class="n">sited</span><span class="p">,</span><span class="w"> </span><span class="n">getLatData</span><span class="p">().</span><span class="n">vol3</span><span class="p">,</span><span class="w"> </span><span class="n">t</span><span class="p">,</span><span class="w"> </span><span class="n">tmp</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">divmod</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span><span class="w">   </span><span class="n">getLatData</span><span class="p">().</span><span class="n">vol2</span><span class="p">,</span><span class="w"> </span><span class="n">z</span><span class="p">,</span><span class="w"> </span><span class="n">tmp</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">divmod</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span><span class="w">   </span><span class="n">getLatData</span><span class="p">().</span><span class="n">vol1</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">,</span><span class="w"> </span><span class="n">x</span><span class="p">);</span><span class="w"></span>

<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">par</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="o">!</span><span class="n">isOdd</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="o">!</span><span class="n">isOdd</span><span class="p">(</span><span class="n">y</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">t</span><span class="p">))</span><span class="w"></span>
<span class="w">        </span><span class="o">++</span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="o">!</span><span class="n">par</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="o">!</span><span class="n">isOdd</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="n">isOdd</span><span class="p">(</span><span class="n">y</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">t</span><span class="p">))</span><span class="w"></span>
<span class="w">        </span><span class="o">++</span><span class="n">x</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="n">sitexyzt</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">,</span><span class="w"> </span><span class="n">z</span><span class="p">,</span><span class="w"> </span><span class="n">t</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>
</div>
</section>
<section id="custom-data-types-to-store-indices">
<h2>Custom data types to store indices<a class="headerlink" href="#custom-data-types-to-store-indices" title="Permalink to this headline"></a></h2>
<p>In <code class="docutils literal notranslate"><span class="pre">SIMULATeQCD</span></code>, there are four <code class="docutils literal notranslate"><span class="pre">struct</span></code>s that can store the spacetime coordinates and the corresponding memory index of a given lattice site:</p>
<p><code class="docutils literal notranslate"><span class="pre">gSite</span></code>:
This <code class="docutils literal notranslate"><span class="pre">struct</span></code> stores the spacetime coordinates and memory index for one lattice site.
More specifically, it stores</p>
<ul class="simple">
<li><p>the 1-<span class="math notranslate nohighlight">\(d\)</span> memory index of the bulk sub-lattice (<code class="docutils literal notranslate"><span class="pre">isite</span></code>)</p></li>
<li><p>the 1-<span class="math notranslate nohighlight">\(d\)</span> memory index of the full sub-lattice (<code class="docutils literal notranslate"><span class="pre">isiteFull</span></code>)</p></li>
<li><p>the spacetime coordinates of the lattice site on the bulk sublattice (<code class="docutils literal notranslate"><span class="pre">coords</span></code>)</p></li>
<li><p>the spacetime coordinates fo the lattice site on the full sublattice (<code class="docutils literal notranslate"><span class="pre">coordsFull</span></code>)</p></li>
</ul>
<p>You can create <code class="docutils literal notranslate"><span class="pre">gSite</span></code> objects using the static class <code class="docutils literal notranslate"><span class="pre">GIndexer</span></code> (see below). You need to remember with which template parameters
you create <code class="docutils literal notranslate"><span class="pre">gSite</span></code> objects, as they don’t store any information about that.
If you read somewhere something like “This function takes an odd <code class="docutils literal notranslate"><span class="pre">gSite</span></code> as input”, then that means that the <code class="docutils literal notranslate"><span class="pre">gSite</span></code>
should have been created using <code class="docutils literal notranslate"><span class="pre">GIndexer&lt;Odd,myHaloDepth&gt;</span></code>.</p>
<div class="toggle admonition">
<p class="admonition-title">Temp</p>
<p><strong>The static class <code class="docutils literal notranslate"><span class="pre">GIndexer</span></code></strong></p>
<p><strong>getSite</strong></p>
<p>With getSite, you can convert an <code class="docutils literal notranslate"><span class="pre">isite</span></code> to a <code class="docutils literal notranslate"><span class="pre">sitexzyt</span></code> and the other way round. You will not directly obtain on or the other, but a <code class="docutils literal notranslate"><span class="pre">gSite</span></code> object that holds both the thing you input as well as the corresponding counterpart.</p>
<p>Let’s say <code class="docutils literal notranslate"><span class="pre">vol4</span></code> is the number of lattice sites.</p>
<p><strong>Basic functionality (no halos, local lattice)</strong></p>
<p><strong>Loop over all sites, or just even/odd part</strong></p>
<div class="highlight-C++ notranslate"><div class="highlight"><pre><span></span><span class="n">LatLayout</span><span class="w"> </span><span class="n">myLayout</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">All</span><span class="p">;</span><span class="w"></span>
<span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">size_t</span><span class="w"> </span><span class="n">isite</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">isite</span><span class="o">&lt;</span><span class="n">vol4</span><span class="p">;</span><span class="w"> </span><span class="n">isite</span><span class="o">++</span><span class="p">){</span><span class="w"></span>

<span class="n">gSite</span><span class="w"> </span><span class="n">mysite</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">GIndexer</span><span class="o">&lt;</span><span class="n">myLayout</span><span class="p">,</span><span class="n">HaloDepth</span><span class="o">&gt;::</span><span class="n">getSite</span><span class="p">(</span><span class="n">isite</span><span class="p">);</span><span class="w"></span>

<span class="c1">//&lt;do something with gSite here...&gt;</span>
<span class="p">}</span><span class="w"></span>
</pre></div>
</div>
<p>The <strong>first half of the sites (from <code class="docutils literal notranslate"><span class="pre">isite=0</span></code> to <code class="docutils literal notranslate"><span class="pre">isite=vol4/2-1</span></code>) are even</strong>, and the <strong>second half (from <code class="docutils literal notranslate"><span class="pre">isite=vol4/2</span></code> to <code class="docutils literal notranslate"><span class="pre">isite=vol4-1</span></code>) are odd</strong> , so you can adjust the start and end values of <code class="docutils literal notranslate"><span class="pre">isite</span></code> accordingly if you only want to loop over the even/odd part.</p>
<p>Examples for even sites:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">0</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">0</span>
<span class="mi">2</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">0</span>
<span class="mi">4</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">0</span>
<span class="o">...</span>
<span class="mi">19</span> <span class="mi">17</span> <span class="mi">19</span> <span class="mi">15</span>
<span class="o">...</span>
<span class="mi">20</span> <span class="mi">20</span> <span class="mi">20</span> <span class="mi">20</span>
</pre></div>
</div>
<p>Example for odd sites:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">1</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">0</span>
<span class="mi">3</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">0</span>
<span class="mi">5</span> <span class="mi">0</span> <span class="mi">0</span> <span class="mi">0</span>
<span class="o">...</span>
<span class="mi">19</span> <span class="mi">17</span> <span class="mi">19</span> <span class="mi">20</span>
<span class="o">...</span>
<span class="mi">19</span> <span class="mi">20</span> <span class="mi">20</span> <span class="mi">20</span>
</pre></div>
</div>
<p>If you need to get the odd (even) sites, although you are looping from <code class="docutils literal notranslate"><span class="pre">isite=0</span></code> to <code class="docutils literal notranslate"><span class="pre">isite=vol4/2-1</span></code> (from <code class="docutils literal notranslate"><span class="pre">isite=vol4/2</span></code> to <code class="docutils literal notranslate"><span class="pre">isite=vol4-1</span></code>), you can simply change the template parameters of the GIndexer to:</p>
<div class="highlight-C++ notranslate"><div class="highlight"><pre><span></span><span class="n">GIndexer</span><span class="o">&lt;</span><span class="n">Odd</span><span class="p">,</span><span class="n">HaloDepth</span><span class="o">&gt;</span><span class="w"></span>
<span class="n">or</span><span class="w"></span>
<span class="n">GIndexer</span><span class="o">&lt;</span><span class="n">Even</span><span class="p">,</span><span class="n">HaloDepth</span><span class="o">&gt;</span><span class="w"></span>
</pre></div>
</div>
<p>With <code class="docutils literal notranslate"><span class="pre">LatLayout</span> <span class="pre">Even</span></code> (<code class="docutils literal notranslate"><span class="pre">Odd</span></code>) you will always get an even (odd) site from the GIndexer, even if you put in an <code class="docutils literal notranslate"><span class="pre">isite</span></code> which refers to an odd (even) site.</p>
</div>
</section>
</section>


           </div>
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2021, LatticeQCD.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>